<?php

/*
	Class: Watch_SubscribeController

	About: Author
		Rich Joslin

	About: License
		<http://communit.as/docs/license>
*/
class Watch_SubscribeController extends Cts_Controller_Action_Abstract {

	/* Group: Instance Methods */

	function init(){
		parent::init();
	}

	/* Group: Actions */

	/*
		Function: index
			Displays a list of subscriptions. A user may delete subscriptions or change subscription preferences.

		View Variables:
			subscriptions - An array of subscriptions.
	*/
	function indexAction() {
		$username = $this->_identity->username;
		$subscriptions_table = new WatchSubscriptions();
		$this->view->subscriptions = $subscriptions_table->getSubscriptions($username);
	}

	/*
		Function: insert
			Inserts a content subscription.

		View Variables:
			tablename - The name of the database table to subscribe to.
			itemid - The ID of the row in the database to subscribe to.
			result - A string showing the result of the attempt to add the subscription.
	*/
	function insertAction() {
		$request = new Cts_Request($this->getRequest());
		$tablename = $request->tablename; // $this->_request->getParam('tablename');
		$itemid = $request->itemid; // (integer)$this->_request->getParam('itemid');
		$username = $this->_identity->username;
		$favs_table = new WatchSubscriptions();
		$favs_table->insertSubscription($username, $tablename, $itemid);
		$this->view->tablename = $tablename;
		$this->view->itemid = $itemid;
		$this->view->result = 'Favorite added';
	}

	/*
		Function: delete
			Deletes a content subscription.

		View Variables:
			tablename - The name of the table used in the subscription that is to be deleted.
			itemid - The row ID used in the subscription that is to be deleted.
			result - A string showing the result of the attempt to delete the subscription.
	*/
	function deleteAction() {
		$request = new Cts_Request($this->getRequest());
		$tablename = $request->tablename;
		$itemid = $request->itemid;
		$username = $this->_identity->username;
		$favs_table = new WatchSubscriptions();
		$favs_table->deleteSubScription($username, $tablename, $itemid);
		$isajax = $this->_request->getParam('isajax');
		$this->view->tablename = $tablename;
		$this->view->itemid = $itemid;
		$this->view->result = 'Favorite removed';
	}

}
